package com;


/**
 *
 */
public class RedisTest {

    public static void main(String[] args) throws Exception {
//        SpringApplication.run(RedisTest.class);
        final SuWeiJedisService suWeiJedisService = new SuWeiJedisService();
        suWeiJedisService.setJedisPropertiesPath("config/jedis.properties");
        suWeiJedisService.initJedisService();


        // set  key  expaird  5 seconds
        suWeiJedisService.suwei_set("key", "65".getBytes(), 5);
        String value;
        value = suWeiJedisService.get("key");
        System.out.println("from redis value:"+value);
        System.out.println("sleep 5 seconds... ...");
        Thread.sleep(5000);//sleep 5 seconds

        value = suWeiJedisService.get("key");
        if (value == null) {
            System.out.println("the key is expire ");
        }else {
            System.out.println("from redis value:"+value);
            Thread.sleep(1000);//sleep 5 seconds
        }
        System.out.println("from redis value:"+suWeiJedisService.get("key"));


//        for (int i = 0; i != 100; ++i) {
//            final Thread thread = new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    for (; ; ) {
//                        try {
//                            Thread.sleep(10);
//                            String name=Thread.currentThread().getName();
//                            suWeiJedisService.set(name, name);
//                            suWeiJedisService.del(name);
//                        } catch (InterruptedException e) {
//                            e.printStackTrace();
//                        }
//                    }
//                }
//            });
//            thread.setName("thead:" + i);
//            thread.start();
//        }
    }
}
